﻿<?php

 header("Access-Control-Allow-Origin:*");
 header("Access-Control-Allow-Headers:X-Requested-With");

include_once './api/include/Wechat.php';

$options = array( 
	'appid'=>'wx7c399150c98e4174', 
	'appsecret'=>'3b61b44cc8c37ecaaa705efdc64dc6f9'
);


$weObj = new Wechat($options);
$weObj->checkAuth();

//授权登陆
if('oauth'==$_GET['ac']){
	$url = $weObj->getOauthRedirect('http://api.weixinzjit.com/shell.php?ac=oauthback');
	_H($url);
	//_JSON(true,'oauth',$url);
} 
//授权登陆回调
elseif('oauthback'==$_GET['ac']){ 
	$data = $weObj->getOauthAccessToken();
	$user = $weObj->getOauthUserinfo($data['access_token'],$data['openid']);
	//_D($user);
	$url = 'http://shellnew.weixinzjit.com/shellnew/index.html?data='.urlencode(json_encode($user));
	echo '<script>location.href="'.$url.'"</script>';
	exit();
	//_JSON(true,'oauthback',$user);
}
//获取分享JS配置
elseif('get_JSAPI_Config'==$_GET['ac']){
	$url =  $_GET['callback'];
	$jsSign = $weObj->getJsSign($url);
	$jsSign['jsapi_ticket'] = $weObj->jsapi_ticket;
	_JSON(true,'get_JSAPI_Config',$jsSign);
}

function _JSON($status,$mes,$data){
	$s = empty($status)?false:$status;
	$m = empty($mes)?false:$mes;
	$d = empty($data)?false:$data;
	exit(json_encode(array('s'=>$s,'m'=>$m,'d'=>$d)));
}
function _D($data){
	echo '<pre>';
	if(is_string($data)){
		echo $data;
	}elseif(is_object($data)){
		var_dump($data);
	}elseif(is_array($data)){
		print_r($data);
	}
	exit();
}

function _H($url){
	header('location:'.$url);
}

 
?>